<?php namespace Common\Model; 

use Hdphp\Model\Model;

//地址管理模型
class Address extends Model{
	// 指定表名
	protected $table='uaddress';
	// 自动验证
	protected $validate=array(
		array('username','required','用户名不能为空',3,3),
		array('address','required','请填写收货地址',3,3),
		array('postcode','required','请填写邮编',3,3),
		array('phone','required','请填写联系电话',3,3),
		);


	public function store(){
		// 获取地址
		$province=Q('post.s_province');
		$city=Q('post.s_city');
		$county=Q('post.s_county');
		$address=Q('post.address');
		// 组合地址
		$address=$province.$city.$address;
		// sp($address);
		$data=array(
			'address'=>$address,
			'postcode'=>Q('post.postcode'),
			'phone'=>Q('post.phone'),
			'username'=>Q('post.username'),
			'user_uid'=>$_SESSION['uid'],
			);
		// sp($data);
		if(!$this->create()) return false;
		// 添加订单表数据并且获得订单的自增ID
		$this->add($data);
		return true;
		
	}
}